package com.info33.platform.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.system.dto.SysAuthorityDetailDTO;
import com.info33.platform.system.dto.SysMenuUserDTO;
import com.info33.platform.system.entity.SysMenuUser;
import com.info33.platform.system.service.SysMenuUserService;
import com.info33.platform.system.vo.SysAuthorityDetailVO;
import com.info33.platform.system.vo.SysAuthorityVO;
import com.info33.platform.system.vo.SysMenuUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
@RestController
@RequestMapping("/SysMenuUser")
@Api(tags = "系统 - 菜单用户")
public class SysMenuUserController extends BaseController<SysMenuUserService, SysMenuUser> {

    private final SysMenuUserService sysMenuUserService;

    @Autowired
    public SysMenuUserController(SysMenuUserService sysMenuUserService) {
        super(sysMenuUserService);
        this.sysMenuUserService = sysMenuUserService;
    }

    @PostMapping(value = "/pageMenuUserList/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页获取菜单权限列表")
    public Result<IPage<SysAuthorityVO>> pageMenuUserList(@RequestBody SysMenuUser sysMenuUser, @PathVariable int pageNum, @PathVariable int pageSize) {
        return Result.ok(sysMenuUserService.pageMenuUserList(new Page<>(pageNum, pageSize), sysMenuUser, getTenantId()));
    }

    @PostMapping("/saveMenuUser")
    @ApiOperation(value = "新增菜单权限")
    public Result<?> saveMenuUser(@RequestBody SysMenuUserDTO sysMenuUserDTO) {
        return sysMenuUserService.saveMenuUser(sysMenuUserDTO, getTenantId());
    }

    @PostMapping("/editMenuUser")
    @ApiOperation(value = "编辑菜单权限")
    public Result<?> editMenuUser(@RequestBody SysMenuUserDTO sysMenuUserDTO) {
        return sysMenuUserService.editMenuUser(sysMenuUserDTO, getTenantId());
    }

    @PostMapping("/batchRemove")
    @ApiOperation(value = "批量删除菜单权限", notes = "批量删除菜单权限")
    public Result<?> batchRemove(@RequestBody List<SysAuthorityDetailDTO> authorityDetailList) {
        return sysMenuUserService.batchRemove(authorityDetailList, getTenantId());
    }

    @PostMapping("/getDetail")
    @ApiOperation(value = "获取菜单权限详情")
    public Result<SysAuthorityDetailVO> getDetail(@RequestBody SysAuthorityDetailDTO sysAuthorityDetailDTO) {
        return Result.ok(sysMenuUserService.getDetail(sysAuthorityDetailDTO, getTenantId()));
    }

    @GetMapping(value = "/getAuthority/{menuId}")
    @ApiOperation(value = "获取菜单对应权限")
    public Result<Map<Integer, List<SysMenuUserVO>>> getAuthority(@PathVariable Long menuId) {
        return Result.ok(sysMenuUserService.getAuthority(menuId));
    }

}